package com.sendpo.zjx.sendpo.fragment;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.model.LatLng;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.github.czy1121.view.CornerLabelView;
import com.gongwen.marqueen.MarqueeFactory;
import com.gongwen.marqueen.MarqueeView;
import com.google.gson.Gson;
import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.jingchen.pulltorefresh.PullableScrollView;
import com.sendpo.zjx.sendpo.R;

import com.sendpo.zjx.sendpo.activity.CreateBusStoreActivity;
import com.sendpo.zjx.sendpo.activity.EditZhaoPinActivity;
import com.sendpo.zjx.sendpo.activity.ExpressHomeActivity;
import com.sendpo.zjx.sendpo.activity.FabuxingChengActivity;
import com.sendpo.zjx.sendpo.activity.GeneicStoreInfoActivity;
import com.sendpo.zjx.sendpo.activity.HelpthingsActivity;
import com.sendpo.zjx.sendpo.activity.LoginActivity;
import com.sendpo.zjx.sendpo.activity.MerchatsActiveInfoActvitiy;
import com.sendpo.zjx.sendpo.activity.PrivateSpeechiActivity;
import com.sendpo.zjx.sendpo.activity.SearchContentActivity;
import com.sendpo.zjx.sendpo.activity.SendBaoMiaoQiangListActivity;
import com.sendpo.zjx.sendpo.activity.SendpoPindanListActivity;
import com.sendpo.zjx.sendpo.activity.SongListActivity;
import com.sendpo.zjx.sendpo.activity.StoreMainAllProduceActivity;
import com.sendpo.zjx.sendpo.activity.ZhaoPinListActivity;
import com.sendpo.zjx.sendpo.domain.BibiliNvgDomain;
import com.sendpo.zjx.sendpo.domain.DynamicDomain;
import com.sendpo.zjx.sendpo.domain.StoreDomain;
import com.sendpo.zjx.sendpo.domain.IndexLocationgetTopDomain;
import com.sendpo.zjx.sendpo.domain.MerchandiseStoreDomain;
import com.sendpo.zjx.sendpo.domain.MerchatsmianDynimcDomain;
import com.sendpo.zjx.sendpo.net.HttpCode;
import com.sendpo.zjx.sendpo.net.HttpUrl;
import com.sendpo.zjx.sendpo.services.AmapLocationService;
import com.sendpo.zjx.sendpo.table.User;
import com.sendpo.zjx.sendpo.utils.Tools;
import com.sendpo.zjx.sendpo.utils.Xutils;
import com.sendpo.zjx.sendpo.views.AutoScrollViewPager;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.common.util.DensityUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2017/7/4.
 */

public class IndexMainFragment extends BaseMainFragment implements AMapLocationListener {
    @BindView(R.id.head_index_left)
    RelativeLayout headIndexLeft;
    @BindView(R.id.head_index_help_iv)
    ImageView headIndexHelpIv;
    @BindView(R.id.indexhlep_bt)
    RelativeLayout indexhlepBt;
    @BindView(R.id.head_index_watchpo_iv)
    ImageView headIndexWatchpoIv;
    @BindView(R.id.index_head)
    RelativeLayout indexHead;
    @BindView(R.id.index_main_imgviewpager)
    AutoScrollViewPager indexMainImgviewpager;


    public static final int[] imgs_dot = new int[]{R.id.dot1, R.id.dot2, R.id.dot3};
    @BindView(R.id.dot1)
    View dot1;
    @BindView(R.id.dot2)
    View dot2;
    @BindView(R.id.dot3)
    View dot3;
    @BindView(R.id.watchstorebt)
    RelativeLayout watchstorebt;
    @BindView(R.id.saoyisaobt)
    ImageView saoyisaobt;
    @BindView(R.id.index_search_left)
    RelativeLayout indexSearchLeft;
    @BindView(R.id.search_edit)
    TextView searchEdit;
    @BindView(R.id.search_edit_bg)
    RelativeLayout searchEditBg;
    @BindView(R.id.index_search_center)
    RelativeLayout indexSearchCenter;

    @BindView(R.id.indexsend_all)
    LinearLayout indexsendAll;

    @BindView(R.id.index_new_left)
    RelativeLayout indexNewLeft;
    @BindView(R.id.index_new_right)
    RelativeLayout indexNewRight;
    @BindView(R.id.index_new_left_view)
    View indexNewLeftView;
    @BindView(R.id.index_new_right_view)
    View indexNewRightView;
    @BindView(R.id.noticehead_mv)
    MarqueeView noticeheadMv;
    @BindView(R.id.index_new_center)
    RelativeLayout indexNewCenter;
    @BindView(R.id.index_new_head_all)
    RelativeLayout indexNewHeadAll;

    @BindView(R.id.fujinsong_bt)
    LinearLayout fujinsongBt;
    @BindView(R.id.daodiansong_bt)
    LinearLayout daodiansongBt;
    @BindView(R.id.qingcangsong_bt)
    LinearLayout qingcangsongBt;
    @BindView(R.id.huodongsong_bt)
    LinearLayout huodongsongBt;
    @BindView(R.id.kaidiansong_bt)
    LinearLayout kaidiansongBt;
    @BindView(R.id.wenjuansong_bt)
    LinearLayout wenjuansongBt;
    @BindView(R.id.dianqingsong_bt)
    RelativeLayout dianqingsongBt;
    @BindView(R.id.fenxiangsong_bt)
    RelativeLayout fenxiangsongBt;

    @BindView(R.id.tiyansong_bt)
    RelativeLayout tiyansongBt;

    View rootView = null;
    @BindView(value = R.id.index_dajianjiaall)
    LinearLayout index_dajianjiaall;
    @BindView(value = R.id.tuijian_recycler)
    public RecyclerView tuijian_recycler;
    public LinearLayoutManager tuijian_lm;
    @BindView(R.id.meriv_01)
    ImageView meriv01;
    @BindView(R.id.meriv_02)
    ImageView meriv02;
    @BindView(R.id.meriv_03)
    ImageView meriv03;
    @BindView(R.id.meriv_04)
    ImageView meriv04;
    @BindView(R.id.meriv_05)
    ImageView meriv05;
    @BindView(R.id.meriv_06)
    ImageView meriv06;
    @BindView(R.id.meriv_07)
    ImageView meriv07;
    @BindView(R.id.meriv_08)
    ImageView meriv08;
    @BindView(R.id.meriv_09)
    ImageView meriv09;

    @BindView(R.id.song_noticehead_mv)
    MarqueeView songNoticeheadMv;
    @BindView(R.id.index_song_right)
    RelativeLayout indexSongRight;
    @BindView(R.id.index_song_left_view)
    View indexSongLeftView;
    @BindView(R.id.index_song_right_view)
    View indexSongRightView;
    @BindView(R.id.index_song_center)
    RelativeLayout indexSongCenter;
    @BindView(R.id.index_song_head_all)
    RelativeLayout indexSongHeadAll;
    @BindView(R.id.remai_recyclerview)
    RecyclerView remai_recyclerview;
    LinearLayoutManager choujiang_lm;
    MerRecylcerAdaper merRecylcerAdaper;
    @BindView(R.id.mertv_01)
    TextView mertv01;
    @BindView(R.id.mertv_02)
    TextView mertv02;
    @BindView(R.id.mertv_03)
    TextView mertv03;

    @BindView(R.id.mertv_04)
    TextView mertv04;
    @BindView(R.id.mertv_05)
    TextView mertv05;
    @BindView(R.id.mertv_06)
    TextView mertv06;
    @BindView(R.id.mertv_07)
    TextView mertv07;
    @BindView(R.id.mertv_08)
    TextView mertv08;
    @BindView(R.id.mertv_09)
    TextView mertv09;
    private MerchatsDynmicRecylcerAdaper tuijian_adpter;
    public int pagenow = 1;

    public String userCity = "";
    private AmapLocationService amapLocationService;
   @BindView(value = R.id.pulltofresh)
   public PullToRefreshLayout pulltofresh;
    public View refreshhead;
    public TextView state_tv;
    @BindView(value = R.id.nestscroll)
    public PullableScrollView nestscroll;
    private boolean isloading;

    @Override
    public View initView() {
        View view = View.inflate(mActivity, R.layout.fragment_index, null);
        ButterKnife.bind(view, mActivity);
        return view;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        if (rootView == null) {
            rootView = super.onCreateView(inflater, container, savedInstanceState);
            ButterKnife.bind(this, rootView);
            initData();
        }
        return rootView;
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }
    public void initData() {
        choujiang_lm = new LinearLayoutManager(mActivity, OrientationHelper.HORIZONTAL,false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        remai_recyclerview.setLayoutManager(choujiang_lm);
        tuijian_lm = new LinearLayoutManager(mActivity, OrientationHelper.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        tuijian_recycler.setLayoutManager(tuijian_lm);

        indexMainImgviewpager.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        indexMainImgviewpager.stopAutoScroll();
                     pulltofresh.setPullDownEnable(false);
                        return true;
                    case MotionEvent.ACTION_MOVE:
                        pulltofresh.setPullDownEnable(false);
                        break;
                    case MotionEvent.ACTION_UP:
                        pulltofresh.setPullDownEnable(false);
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        indexMainImgviewpager.startAutoScroll();
                        pulltofresh.setPullDownEnable(true);
                        break;
                }
                return false;
            }
        });
        nestscroll.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()){
                    case MotionEvent.ACTION_MOVE:
                        int scrollY=view.getScrollY();
                        int height=view.getHeight();
                        int scrollViewMeasuredHeight=nestscroll.getChildAt(0).getMeasuredHeight();
                        if(scrollY==0){
                            System.out.println("*******************滑动到了顶端 view.getScrollY()="+scrollY);
                        }
                        if((scrollY+height)==scrollViewMeasuredHeight){
                            if(tuijian_adpter!=null&&tuijian_adpter.dataBeen.size()>=6&&isloading==false){
                                pagenow++;
                                iniTuijianAppend(userCity,pagenow);

                            }

                        }
                        break;
                }
                return false;
            }
        });
        pulltofresh.setPullDownEnable(true);
        pulltofresh.setPullUpEnable(false);
        refreshhead =View.inflate(mActivity,R.layout.myrefresh_head,null);
        state_tv=refreshhead.findViewById(R.id.state_tv);
        pulltofresh.setCustomRefreshView(refreshhead);
        pulltofresh.setOnRefreshProcessListener(new PullToRefreshLayout.OnPullProcessListener() {
            @Override

            public void onPrepare(View v, int which) {

            }

            @Override
            public void onStart(View v, int which) {

            }

            @Override
            public void onHandling(View v, int which) {

            }

            @Override
            public void onFinish(View v, int which) {

            }

            @Override
            public void onPull(View v, float pullDistance, int which) {
                state_tv.setText("下拉刷新");
            }
        });
        pulltofresh.setOnPullListener(new PullToRefreshLayout.OnPullListener() {
            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
                state_tv.setText("刷新中......");
                amapLocationService = new AmapLocationService(mActivity);
                amapLocationService.setmLocationOption(getDefaultAmapLocationOptions());
                amapLocationService.registerListener(IndexMainFragment.this);
                amapLocationService.start();
            }
            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {

            }
        });
        pulltofresh.autoRefresh();


    }

    public AMapLocationClientOption getDefaultAmapLocationOptions() {
        AMapLocationClientOption mLocationOption = null;
        if (mLocationOption == null) {
            mLocationOption = new AMapLocationClientOption();
            //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
            mLocationOption.setLocationCacheEnable(true);
            mLocationOption.setOnceLocation(true);
            mLocationOption.setOnceLocationLatest(false);
            //设置是否返回地址信息（默认返回地址信息）
            mLocationOption.setNeedAddress(true);
            //设置是否强制刷新WIFI，默认为true，强制刷新。
            mLocationOption.setWifiScan(true);
            mLocationOption.setInterval(1000);
            //单位是毫秒，默认30000毫秒，建议超时时间不要低于8000毫秒。
            mLocationOption.setHttpTimeOut(20000);
        }
        return mLocationOption;
    }

  //商品导航条
    public void nvg() {
        String cache_result = Tools.getCache(mActivity, HttpUrl.getBilling+"indexlocation:1");
        Gson gson = new Gson();
        if (cache_result != null && !cache_result.equals("")) {
            BibiliNvgDomain cache_domain = gson.fromJson(cache_result, BibiliNvgDomain.class);
            if (cache_domain.getFlag()) {
                if (cache_domain.getData() != null && cache_domain.getData().size() >= 3) {
                    Tools.setCache(mActivity, HttpUrl.getBilling + "location:1", cache_result);
                    List<ImageView> imageViews = new ArrayList<>();
                    for (int i = 0; i < 3; i++) {
                        final BibiliNvgDomain.Data dataBean = cache_domain.getData().get(i);
                        ImageView iv = new ImageView(mActivity);
                        iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                        imageViews.add(iv);
                        Glide.with(mActivity)
                                .load("" + dataBean.getImg())
                                .asBitmap()
                                .placeholder(getResources().getColor(R.color.default_lightgray))
                                .animate(R.anim.fade_in)
                                .into(iv);
                        iv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("merchandiseId", dataBean.getId());
                                Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                            }
                        });

                    }
                    indexMainImgviewpager.setAdapter(new ImgBannerViewpagerAdpater(imageViews));
                    indexMainImgviewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                        @Override
                        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                        }

                        @Override
                        public void onPageSelected(int position) {
                            for (int i = 0; i < imgs_dot.length; i++) {
                                View iv = rootView.findViewById(imgs_dot[i]);
                                if (iv != null) {
                                    if (i == position) {
                                        iv.setAlpha(1.0f);
                                    } else {
                                        iv.setAlpha(0.4f);
                                    }
                                }
                            }
                        }

                        @Override
                        public void onPageScrollStateChanged(int state) {

                        }
                    });
                    indexMainImgviewpager.setCurrentItem(0, true);
                    indexMainImgviewpager.setDirection(AutoScrollViewPager.RIGHT);
                    indexMainImgviewpager.setInterval(3000);
                    indexMainImgviewpager.setAutoScrollDurationFactor(10);
                    indexMainImgviewpager.startAutoScroll(3000);

                }
                }

        }


        Map<String, String> map = new HashMap<>();
        map.put("location","1");
        Xutils.GET(HttpUrl.getBilling, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                state_tv.setText("刷新完成");
                pulltofresh.refreshFinish(PullToRefreshLayout.SUCCEED);
                Gson gson=new Gson();
                BibiliNvgDomain cache_domain = gson.fromJson(result, BibiliNvgDomain.class);
                if (cache_domain.getFlag()) {
                    if (cache_domain.getData() != null && cache_domain.getData().size() >= 3) {
                        Tools.setCache(mActivity, HttpUrl.getBilling+"indexlocation:1", result);
                        List<ImageView> imageViews = new ArrayList<>();
                        for (int i = 0; i < 3; i++) {
                            final BibiliNvgDomain.Data dataBean = cache_domain.getData().get(i);
                            ImageView iv = new ImageView(mActivity);
                            iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                            imageViews.add(iv);
                            Glide.with(mActivity)
                                    .load("" + dataBean.getImg())
                                    .asBitmap()
                                    .placeholder(getResources().getColor(R.color.default_lightgray))
                                    .animate(R.anim.fade_in)
                                    .into(iv);
                            iv.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Map<String, Object> map = new HashMap<>();
                                    map.put("merchandiseId", dataBean.getId());
                                    Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                                }
                            });

                        }
                        indexMainImgviewpager.setAdapter(new ImgBannerViewpagerAdpater(imageViews));
                        indexMainImgviewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                            @Override
                            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                            }
                            @Override
                            public void onPageSelected(int position) {
                                for (int i = 0; i < imgs_dot.length; i++) {
                                    View iv = rootView.findViewById(imgs_dot[i]);
                                    if (iv != null) {
                                        if (i == position) {
                                            iv.setAlpha(1.0f);
                                        } else {
                                            iv.setAlpha(0.4f);
                                        }
                                    }
                                }
                            }
                            @Override
                            public void onPageScrollStateChanged(int state) {

                            }
                        });
                        indexMainImgviewpager.setCurrentItem(0, true);
                        indexMainImgviewpager.setDirection(AutoScrollViewPager.RIGHT);
                        indexMainImgviewpager.setInterval(3000);
                        indexMainImgviewpager.setAutoScrollDurationFactor(10);
                        indexMainImgviewpager.startAutoScroll(3000);
                    }


                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                state_tv.setText("刷新失败");
                pulltofresh.refreshFinish(PullToRefreshLayout.FAIL);
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        if (aMapLocation == null) {
            Toast.makeText(mActivity.getApplicationContext(), "定位失败", Toast.LENGTH_SHORT).show();
         pulltofresh.refreshFinish(PullToRefreshLayout.FAIL);
            return;
        }
        userCity = aMapLocation.getCity();
        pagenow=1;
        nvg();
        merchandisebylocation(userCity);
        merchandiseindexlocationgetTop(aMapLocation.getDistrict(), userCity);
        merchandisebyremai(userCity);
        merchandisebydajianjia(userCity);
        iniTuijian(userCity,pagenow);
    }


    private class ImgBannerViewpagerAdpater extends PagerAdapter {
        public List<ImageView> imageViews;

        public ImgBannerViewpagerAdpater(List<ImageView> imageViews) {
            this.imageViews = imageViews;
        }

        @Override
        public int getCount() {
            return imageViews.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView iv = imageViews.get(position);
            container.addView(iv);
            return iv;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            //super.destroyItem(container, position, object);
            ImageView iv = imageViews.get(position);
            container.removeView(iv);
        }
    }

    public class NoticeMF extends MarqueeFactory<TextView, String> {
        private LayoutInflater inflater;

        public NoticeMF(Context mContext) {
            super(mContext);
            inflater = LayoutInflater.from(mContext);
        }

        @Override
        public TextView generateMarqueeItemView(String data) {
            TextView mView = (TextView) inflater.inflate(R.layout.notice_item, null);

            String datas = null;
            int merchandiseId = 0;
            try {
                JSONObject jsonObject = new JSONObject(data);
                datas = jsonObject.getString("data");
                merchandiseId = jsonObject.getInt("merchandiseId");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            mView.setText(datas);
            final int finalMerchandiseId = merchandiseId;

            return mView;

        }
    }

    @Override
    public void onStart() {
        super.onStart();
//        if (indexMainImgviewpager != null) {
//            indexMainImgviewpager.startAutoScroll();
//        }
//        if (noticeheadMv != null) {
//            noticeheadMv.startFlipping();
//        }
//        if (songNoticeheadMv != null) {
//            songNoticeheadMv.startFlipping();
//        }

    }

    @Override
    public void onStop() {
        super.onStop();
//        if (indexMainImgviewpager != null) {
//            indexMainImgviewpager.stopAutoScroll();
//        }
//        if (noticeheadMv != null) {
//            noticeheadMv.stopFlipping();
//        }
//        if (songNoticeheadMv != null) {
//            songNoticeheadMv.stopFlipping();
//        }

    }

    @OnClick(value = {R.id.head_index_left, R.id.indexhlep_bt, R.id.saoyisaobt, R.id.watchstorebt,

            R.id.search_edit, R.id.index_new_right,

            R.id.index_song_right,
         R.id.zhihuidingzhi_bt,R.id.index_zhaorenbt,R.id.index_woyaofahuobt,
    R.id.index_jiedanyunhuoobt,R.id.index_pindanyouhuibt,R.id.index_woyaoqiuzhibt,
    R.id.fujinsong_bt,
    R.id.daodiansong_bt,
    R.id.qingcangsong_bt,
    R.id.huodongsong_bt,
    R.id.kaidiansong_bt,
    R.id.wenjuansong_bt,
    R.id.dianqingsong_bt,
    R.id.tiyansong_bt,
    R.id.fenxiangsong_bt})
    public void onMyClick(View view) {
        Map<String,Object> data=new HashMap<>();
        switch (view.getId()) {
            case R.id. index_zhaorenbt:
                Tools.redirectActivity(mActivity, HelpthingsActivity.class);
                break;
            case R.id.index_woyaofahuobt:
                Tools.redirectActivity(mActivity, ExpressHomeActivity.class);
                break;
            case R.id.index_jiedanyunhuoobt:
            Tools.redirectActivity(mActivity, FabuxingChengActivity.class);

                break;
            case R.id.index_pindanyouhuibt:
                List<User> userList=Xutils.queryAll(getActivity().getApplication(),User.class);
                if(userList==null||userList.size()==0){
                    Tools.redirectActivity(mActivity, LoginActivity.class);
                    return;
                }
                switch (userList.get(0).getMerchantsState()){
                    case 0:
                        Tools.redirectActivity(this.mActivity, CreateBusStoreActivity.class);
                        break;
                    case 1:
                        Toast.makeText(this.mActivity.getApplicationContext(), "店铺实名审核中", Toast.LENGTH_SHORT).show();
                        break;

                    case 2:
                        Tools.redirectActivity(this.mActivity, EditZhaoPinActivity.class);

                        break;
                    case 3:
                        Toast.makeText(this.mActivity.getApplicationContext(), "店铺审核实名失败", Toast.LENGTH_SHORT).show();
                        Tools.redirectActivity(this.mActivity, CreateBusStoreActivity.class);
                        break;
                }
                break;
            //我要求职
            case R.id.index_woyaoqiuzhibt:
            Tools.redirectActivity(mActivity, ZhaoPinListActivity.class);
                break;
                //私人订制
            case R.id.zhihuidingzhi_bt:
                Tools.redirectActivity(mActivity, PrivateSpeechiActivity.class);
                break;


            case R.id.index_new_right:
                Tools.redirectActivity(mActivity, SendBaoMiaoQiangListActivity.class);
                break;
            //打开选择城市
            case R.id.head_index_left:
                mActivity.openSelecterLocation();
                break;
            //打开帮助界面
            case R.id.indexhlep_bt:
             Tools.redirectActivity(mActivity, HelpthingsActivity.class);
                break;
            case R.id.saoyisaobt:
                mActivity.openCamera();
                break;
            //看宝
            case R.id.watchstorebt:

                mActivity. setStyleItem(2);

                break;


            case R.id.search_edit:
                 Tools.redirectActivity(mActivity, SearchContentActivity.class);
                break;

            case R.id.index_song_right:

                data.put("posiiton",0);
                  Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.fujinsong_bt:
                data.put("posiiton",0);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.daodiansong_bt:
                data.put("posiiton",1);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.qingcangsong_bt:
                data.put("posiiton",2);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.huodongsong_bt:
                data.put("posiiton",3);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.kaidiansong_bt:
                data.put("posiiton",4);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.wenjuansong_bt:
                data.put("posiiton",5);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.dianqingsong_bt:
                data.put("posiiton",6);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;
            case R.id.tiyansong_bt:
                data.put("posiiton",7);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;

            case R.id.fenxiangsong_bt:
                data.put("posiiton",8);
                Tools.redirectActivity(mActivity, SongListActivity.class,data);
                break;

        }
    }


    public class MerRecylcerAdaper extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        public List<StoreDomain.Data> dataBeen;
        public LayoutInflater inflater;

        public MerRecylcerAdaper(List<StoreDomain.Data> dataBeen, Context context) {
            inflater = LayoutInflater.from(context);
            this.dataBeen = dataBeen;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            RecyclerView.ViewHolder ih = null;
            ih = new IndexHoler(inflater.inflate(R.layout.layout_index_sendpoitem, parent, false));
            return ih;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
            final IndexHoler ih = (IndexHoler) holder;
            final StoreDomain.Data dataBean = dataBeen.get(position);
            ih.name.setText("" + dataBean.getName());
            Glide.with(mActivity)
                    .load("" + dataBean.getImg())
                    .asBitmap()
                    .animate(R.anim.fade_in)
                    .override(500, 500)
                    .into(ih.img);
            ih.realmoney.setText("¥" + dataBean.getPrice());
            ih.originmoney.setText("¥" + dataBean.getOriginalPrice());

            ih.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("merchandiseId", dataBean.getId());
                  Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                }
            });
        }

        @Override
        public int getItemCount() {
            return dataBeen.size();
        }

        public class IndexHoler extends RecyclerView.ViewHolder {
            public View rootView;
             public ImageView img;
          public TextView name;
          public TextView realmoney;
          public TextView originmoney;
            public IndexHoler(View itemView) {
                super(itemView);
                rootView=itemView;
                img=itemView.findViewById(R.id.img);
                name=itemView.findViewById(R.id.name);
                realmoney=itemView.findViewById(R.id.realmoney);
                originmoney=itemView.findViewById(R.id.originmoney);
                originmoney.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
                originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
                originmoney.getPaint().setAntiAlias(true);// 抗锯齿
                originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
            }
        }

        public void deleteRow(int position) {
            dataBeen.remove(position);
            notifyDataSetChanged();
        }

        public void initRefresh(List<StoreDomain.Data> domains) {
            this.dataBeen.removeAll(this.dataBeen);
            this.dataBeen.addAll(domains);
            notifyDataSetChanged();
        }

        public void initAppend(List<StoreDomain.Data> domains) {
            this.dataBeen.addAll(domains);
            notifyDataSetChanged();
        }

        public void delete(int position) {
            this.dataBeen.remove(position);
            notifyDataSetChanged();
        }


    }

    public class MerchatsDynmicRecylcerAdaper extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        public List<DynamicDomain.DataBean> dataBeen;
        public LayoutInflater inflater;

        public MerchatsDynmicRecylcerAdaper(List<DynamicDomain.DataBean> dataBeen, Context context) {
            inflater = LayoutInflater.from(context);
            this.dataBeen = dataBeen;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            RecyclerView.ViewHolder ih = null;
            ih = new IndexHoler(inflater.inflate(R.layout.layout_juagesendpo_item, parent, false));
            return ih;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
            final IndexHoler ih = (IndexHoler) holder;
            final DynamicDomain.DataBean dataBean = dataBeen.get(position);
            ih.juage_img_iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("merchantsId", dataBean.getMerchantsId());
               Tools.redirectActivity(mActivity, StoreMainAllProduceActivity.class, map);
                }
            });
            ih.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Map<String, Object> map = new HashMap<>();
                    MerchatsmianDynimcDomain.DataBean  dataBean1=new MerchatsmianDynimcDomain.DataBean();
                    dataBean1.setMerchantsDyId(dataBean.getId());
                    map.put("data", dataBean1);
                  Tools.redirectActivity(mActivity, MerchatsActiveInfoActvitiy.class, map);
                }
            });
            ih.all_ll.removeAllViews();
            List<String> imgs = dataBean.getImgs();
            if (imgs != null && imgs.size() != 0) {
                final List<String> ivs_s = new ArrayList<>();
                final List<ImageView> ivs = new ArrayList<>();
                for (String img : imgs) {
                    final ImageView iv = new ImageView(mActivity);
                    iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(DensityUtil.dip2px(100), DensityUtil.dip2px(100));
                    lp.setMargins(0, 0, DensityUtil.dip2px(10), 0);
                    iv.setLayoutParams(lp);
                    iv.setBackgroundColor(getResources().getColor(R.color.default_lightgray));
                    Glide.with(mActivity)
                            .load(img)
                            .asBitmap()
                            .animate(R.anim.fade_in)
                            .placeholder(getResources().getColor(R.color.default_lightgray))
                            .override(500, 500)
                            .into(iv);
                    iv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            mActivity.vImageWatcher.show(iv, ivs, ivs_s);
                        }
                    });
                    ivs.add(iv);
                    ivs_s.add(img);
                    ih.all_ll.addView(iv);
                }
            }
            if (dataBean.isStar()) {
                ih.goods_iv.setImageResource(R.mipmap.yanchu_goodicon_focus);

            } else {
                ih.goods_iv.setImageResource(R.mipmap.yanchu_goodicon);

            }

            ih.goods_bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    List<User> userList = Xutils.queryAll(mActivity.getApplication(), User.class);

                    if (userList == null || userList.size() == 0) {

                      Tools.redirectActivity(mActivity, LoginActivity.class);
                        return;
                    }
                    if (dataBean.isStar()) {
                        ih.goods_iv.setImageResource(R.mipmap.yanchu_goodicon);
                        dataBean.setStar(false);
                        int count = Integer.parseInt(ih.goood_tv.getText().toString().trim() + "");
                        count--;
                        ih.goood_tv.setText(count + "");
                        nofocus(userList.get(0).getUserId() + "", dataBean.getStarId() + "");
                    } else {
                        ih.goods_iv.setImageResource(R.mipmap.yanchu_goodicon_focus);
                        dataBean.setStar(true);
                        int count = Integer.parseInt(ih.goood_tv.getText().toString().trim() + "");
                        count++;
                        ih.goood_tv.setText(count + "");
                        focus(userList.get(0).getUserId() + "", dataBean.getId() + "");
                    }
                }
            });
            ih.goood_tv.setText("" + dataBean.getStarCount());
            ih.guest_tv.setText("" + dataBean.getCommentCount());

                Glide.with(mActivity)
                        .load("" + dataBean.getMerchantsHeadImg())
                        .asBitmap()
                        .placeholder(R.drawable.nim_avatar_default)
                        .animate(R.anim.fade_in)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                ih.juage_img_iv.setImageBitmap(resource);
                            }
                        });
                ih.juage_img_tv.setText("" + dataBean.getMerchantsName() + "");
            ih.datetime.setText("" + dataBean.getCreateDate());
            ih.area.setText("" + dataBean.getArea());
            ih.content.setText("" + dataBean.getContent());
            ih.watchnum.setText("" + dataBean.getLookCount());
            ih.address.setText("");
            LatLng myselflatLng = new LatLng(mActivity.userLatitude, mActivity.userLongitude);
            if (TextUtils.isEmpty(dataBean.getLatitude()) || TextUtils.isEmpty(dataBean.getLongitude())) {
                ih.location.setText("无法得到位置");
                return;
            }
            LatLng latLng = new LatLng(Double.parseDouble(dataBean.getLatitude()), Double.parseDouble(dataBean.getLongitude()));
            int distance = (int) AMapUtils.calculateLineDistance(myselflatLng, latLng);
            if (distance == 0) {
                ih.location.setText("就在附近");
            } else if (distance <= 5) {
                ih.location.setText("不足5m");
            } else {
                 if(distance>=1000){

                     ih.location.setText("距离" +(distance/1000)+ "km");
                 }else{
                     ih.location.setText("距离" + distance + "m");
                 }

            }

        }


        @Override
        public int getItemCount() {
            return dataBeen.size();
        }

        public class IndexHoler extends RecyclerView.ViewHolder {
            public View rootView;
            public LinearLayout all_ll;


            public ImageView goods_iv;

            public RelativeLayout goods_bt;
            public TextView goood_tv;
            public RelativeLayout guest_bt;
            public RelativeLayout watch_bt;
            public TextView guest_tv;
            public CircleImageView juage_img_iv;
            public TextView juage_img_tv;
            public TextView datetime;
            public TextView location;
            public TextView area;
            public TextView content;
            public TextView watchnum;
            public TextView address;

            public IndexHoler(View itemView) {
                super(itemView);
                rootView = itemView;
                address = itemView.findViewById(R.id.address);
                all_ll = itemView.findViewById(R.id.all_ll);
                watchnum = itemView.findViewById(R.id.watchnum);
                goods_iv = itemView.findViewById(R.id.goods_iv);
                goods_bt = itemView.findViewById(R.id.goods_bt);
                goood_tv = itemView.findViewById(R.id.goood_tv);
                guest_bt = itemView.findViewById(R.id.guest_bt);
                watch_bt = itemView.findViewById(R.id.watch_bt);
                guest_tv = itemView.findViewById(R.id.guest_tv);
                juage_img_iv = itemView.findViewById(R.id.juage_img_iv);
                juage_img_tv = itemView.findViewById(R.id.juage_img_tv);
                datetime = itemView.findViewById(R.id.datetime);
                location = itemView.findViewById(R.id.location);
                area = itemView.findViewById(R.id.area);
                content = itemView.findViewById(R.id.content);
                watchnum = itemView.findViewById(R.id.watchnum);
            }
        }

        public void initRefresh(List<DynamicDomain.DataBean> domains) {
            this.dataBeen.removeAll(this.dataBeen);
            this.dataBeen.addAll(domains);
            notifyDataSetChanged();
        }

        public void initAppend(List<DynamicDomain.DataBean> domains) {
            this.dataBeen.addAll(domains);
            notifyDataSetChanged();
        }

        public void delete(int position) {
            this.dataBeen.remove(position);
            notifyDataSetChanged();
        }

        public void focus(String userId, String merchantsDyId) {
            Map<String, String> map = new HashMap<>();
            map.put("userId", "" + userId);
            map.put("merchantsDyId", merchantsDyId);
            Xutils.POST(HttpUrl.chantpraiseAdd, map, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    System.out.println("*************************" + result);
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {

                }

                @Override
                public void onCancelled(CancelledException cex) {

                }

                @Override
                public void onFinished() {

                }
            });

        }

        public void nofocus(String userId, String merchantsDyPraiseId) {

            Map<String, String> map = new HashMap<>();
            map.put("userId", "" + userId);
            map.put("merchantsDyPraiseId", merchantsDyPraiseId);
            Xutils.POST(HttpUrl.chantpraiseDelete, map, new Callback.CommonCallback<String>() {
                @Override
                public void onSuccess(String result) {
                    System.out.println("*************************" + result);
                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {

                }

                @Override
                public void onCancelled(CancelledException cex) {

                }

                @Override
                public void onFinished() {

                }
            });

        }
    }

    //推荐商铺动态
    public void iniTuijian(String userCity,int pagenow) {
        Map<String, String> map = new HashMap<>();
        map.put("page", pagenow + "");
        map.put("pageSize", 6 + "");
         map.put("city", userCity + "");
        List<User> userList = Xutils.queryAll(mActivity.getApplication(), User.class);
        if (userList == null) {
            map.put("userID", 0 + "");
        } else {
            map.put("userID", userList.get(0).getUserId() + "");
        }
        Xutils.GET(HttpUrl.getRecommendDynamic, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                DynamicDomain domain = gson.fromJson(result, DynamicDomain.class);
                 if(domain.isFlag()){
                     if (domain.getData() != null && domain.getData().size() != 0) {
                         Tools.setCache(mActivity, HttpUrl.merchantdynmicbusinessnewupdate, result);
                         if (tuijian_adpter == null) {
                             tuijian_recycler.setAdapter(tuijian_adpter = new MerchatsDynmicRecylcerAdaper(domain.getData(), mActivity));
                         } else {
                             tuijian_adpter.initRefresh(domain.getData());
                         }

                     }
                 }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
    //推荐商铺添加
    public void iniTuijianAppend(String userCity,int pagenow) {
        isloading=true;
        Map<String, String> map = new HashMap<>();
        map.put("page", pagenow + "");
        map.put("pageSize", 6 + "");
        map.put("city", userCity + "");
        List<User> userList = Xutils.queryAll(mActivity.getApplication(), User.class);
        if (userList == null) {
            map.put("userID", 0 + "");
        } else {
            map.put("userID", userList.get(0).getUserId() + "");
        }
        Xutils.GET(HttpUrl.getRecommendDynamic, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                isloading=false;
                Gson gson = new Gson();
                DynamicDomain domain = gson.fromJson(result, DynamicDomain.class);
                if(domain.isFlag()){
                    if (domain.getData() != null && domain.getData().size() != 0) {
                        Tools.setCache(mActivity, HttpUrl.merchantdynmicbusinessnewupdate, result);
                        if (tuijian_adpter == null) {
                            tuijian_recycler.setAdapter(tuijian_adpter = new MerchatsDynmicRecylcerAdaper(domain.getData(), mActivity));
                        } else {
                            tuijian_adpter.initAppend(domain.getData());
                        }

                    }
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                isloading=false;
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //0元抢购
    public void merchandisebylocation(final String userCity) {
        String cache_result = Tools.getCache(mActivity,HttpUrl.getGiveMethod + "indexpagesize:6"+userCity);
        Gson gson = new Gson();
        if (cache_result != null && !cache_result.equals("")) {
            final StoreDomain  domain=gson.fromJson(cache_result,StoreDomain.class);
            if(domain.getFlag()){
                if (domain.getData() != null && domain.getData().size() != 0) {
                    MarqueeFactory marqueeFactory = new NoticeMF(mActivity);
                    List<String> ara = new ArrayList<String>();
                    for (int i = 0; i < domain.getData().size(); i++) {
                        StoreDomain.Data storeDomain = domain.getData().get(i);
                        JSONObject jsonObject = new JSONObject();
                        try {
                            jsonObject.put("merchandiseId", storeDomain.getId());
                            jsonObject.put("data", storeDomain.getName());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        ara.add(jsonObject.toString());
                    }
                    marqueeFactory.resetData(ara);
                    marqueeFactory.setOnItemClickListener(new MarqueeFactory.OnItemClickListener() {
                        @Override
                        public void onItemClickListener(MarqueeFactory.ViewHolder holder) {
                            StoreDomain.Data dataBean = domain.getData().get(holder.position);
                            Map<String, Object> map = new HashMap<>();
                            map.put("merchandiseId",dataBean.getId());
                            Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                        }
                    });
                    noticeheadMv.setMarqueeFactory(marqueeFactory);
                    indexsendAll.removeAllViews();
                    for (int i = 0; i < domain.getData().size(); i++) {
                        final StoreDomain.Data dataBean = domain.getData().get(i);
                        View view = View.inflate(mActivity, R.layout.layout_index_sendpoitem, null);
                        ImageView indeximg = view.findViewById(R.id.img);
                        TextView realmoney = view.findViewById(R.id.realmoney);
                        TextView originmoney = view.findViewById(R.id.originmoney);
                        TextView name = view.findViewById(R.id.name);
                        Glide.with(mActivity).load(dataBean.getImg() + "")
                                .crossFade(1000)
                                .centerCrop()
                                .into(indeximg);
                        originmoney.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
                        originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
                        originmoney.getPaint().setAntiAlias(true);// 抗锯齿
                        originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
                        originmoney.setText("¥" + dataBean.getOriginalPrice());
                        realmoney.setText("¥" + dataBean.getPrice());
                        name.setText("" + dataBean.getName());
                        view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("merchandiseId", dataBean.getId());
                                Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                            }
                        });
                        indexsendAll.addView(view);
                    }
                }
            }

        }
        final Map<String, String> map = new HashMap<>();
        map.put("city", userCity);
        map.put("pageSize","6");
        map.put("giveMethod","0");
        map.put("page","1");
        Xutils.GET(HttpUrl.getGiveMethod, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                System.out.println("******************result"+result);
                Gson gson = new Gson();
                final StoreDomain  domain=gson.fromJson(result,StoreDomain.class);
                     if(domain.getFlag()){
                         if (domain.getData() != null && domain.getData().size() != 0) {
                             Tools.setCache(mActivity, HttpUrl.getGiveMethod + "indexpagesize:6"+userCity, result);
                             MarqueeFactory marqueeFactory = new NoticeMF(mActivity);
                             List<String> ara = new ArrayList<String>();
                             for (int i = 0; i < domain.getData().size(); i++) {
                                 StoreDomain.Data storeDomain = domain.getData().get(i);
                                 JSONObject jsonObject = new JSONObject();
                                 try {
                                     jsonObject.put("merchandiseId", storeDomain.getId());
                                     jsonObject.put("data", storeDomain.getName());
                                 } catch (JSONException e) {
                                     e.printStackTrace();
                                 }
                                 ara.add(jsonObject.toString());
                             }
                             marqueeFactory.resetData(ara);
                             marqueeFactory.setOnItemClickListener(new MarqueeFactory.OnItemClickListener() {
                                 @Override
                                 public void onItemClickListener(MarqueeFactory.ViewHolder holder) {
                                     StoreDomain.Data dataBean = domain.getData().get(holder.position);
                                     Map<String, Object> map = new HashMap<>();
                                     map.put("merchandiseId",dataBean.getId());
                                     Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                                 }
                             });
                             noticeheadMv.setMarqueeFactory(marqueeFactory);
                             indexsendAll.removeAllViews();
                             for (int i = 0; i < domain.getData().size(); i++) {
                                 final StoreDomain.Data dataBean = domain.getData().get(i);
                                 View view = View.inflate(mActivity, R.layout.layout_index_sendpoitem, null);
                                 ImageView indeximg = view.findViewById(R.id.img);
                                 TextView realmoney = view.findViewById(R.id.realmoney);
                                 TextView originmoney = view.findViewById(R.id.originmoney);
                                 TextView name = view.findViewById(R.id.name);
                                 Glide.with(mActivity).load(dataBean.getImg() + "")
                                         .crossFade(1000)
                                         .centerCrop()
                                         .into(indeximg);
                                 originmoney.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
                                 originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
                                 originmoney.getPaint().setAntiAlias(true);// 抗锯齿
                                 originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
                                 originmoney.setText("¥" + dataBean.getOriginalPrice());
                                 realmoney.setText("¥" + dataBean.getPrice());
                                 name.setText("" + dataBean.getName());
                                 view.setOnClickListener(new View.OnClickListener() {
                                     @Override
                                     public void onClick(View view) {
                                         Map<String, Object> map = new HashMap<>();
                                         map.put("merchandiseId",dataBean.getId());
                                         Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                                     }
                                 });
                                 indexsendAll.addView(view);
                             }
                         }
                     }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }



    //附近送。。。。等第一张图片
    public void merchandiseindexlocationgetTop(final String userArea, final String userCity) {
        Map<String, String> map = new HashMap<>();
        map.put("merchantsArea", userArea);
        map.put("merchantsCity", userCity);
        Xutils.POST(HttpUrl.merchandiseindexlocationgetTop, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                final IndexLocationgetTopDomain domain = gson.fromJson(result, IndexLocationgetTopDomain.class);
                switch (domain.getState()) {
                    case HttpCode.SUCCESS:
                        List<String> as = new ArrayList<String>();
                        final List<Integer> ls = new ArrayList<Integer>();
                        if (domain.getData() != null) {
                            Tools.setCache(mActivity, HttpUrl.merchandiseindexlocationgetTop, result);
                            final IndexLocationgetTopDomain.DataBean topDomain = domain.getData();
                            if (topDomain.getMer0() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer0().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv01);
                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer0().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer0().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMe1() != null) {
                                Glide.with(IndexMainFragment.this)
                                        .load("" + topDomain.getMe1().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv02);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMe1().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMe1().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer2() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer2().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv03);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer2().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer2().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());

                            }
                            if (topDomain.getMer3() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer3().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv04);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer3().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer3().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer4() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer4().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv05);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer4().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer4().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer5() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer5().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv06);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer5().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer5().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer6() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer6().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv07);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer6().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer6().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer7() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer7().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv08);

                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer7().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer7().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            if (topDomain.getMer8() != null) {
                                Glide.with(mActivity)
                                        .load("" + topDomain.getMer8().getMerchandiseHeadimg())
                                        .placeholder(getResources().getColor(R.color.default_lightgray))
                                        .override(300, 300)
                                        .animate(R.anim.fade_in)
                                        .into(meriv09);
                                JSONObject jsonObject = new JSONObject();
                                try {
                                    jsonObject.put("merchandiseId", topDomain.getMer8().getMerchandiseId());
                                    jsonObject.put("data", topDomain.getMer8().getMerchandiseDetails());
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                                as.add("" + jsonObject.toString());
                            }
                            MarqueeFactory marqueeFactory = new NoticeMF(mActivity);
                            marqueeFactory.resetData(as);
                            marqueeFactory.setOnItemClickListener(new MarqueeFactory.OnItemClickListener() {
                                @Override
                                public void onItemClickListener(MarqueeFactory.ViewHolder holder) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(holder.data.toString());
                                        Map<String, Object> map = new HashMap<>();
                                        map.put("merchandiseId", jsonObject.getInt("merchandiseId"));
                                    Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                }
                            });
                            songNoticeheadMv.setMarqueeFactory(marqueeFactory);


                        }

                        break;
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //热卖商品
    public void merchandisebyremai(final String userCity) {
        String cache_result = Tools.getCache(mActivity,HttpUrl.getMerchantsHot + "indexpagesize:6");
        Gson gson = new Gson();
        if (cache_result != null && !cache_result.equals("")) {
            final StoreDomain domain = gson.fromJson(cache_result, StoreDomain.class);
            if(domain.getFlag()){
                if (domain.getData() != null && domain.getData().size() != 0) {
                    if (merRecylcerAdaper == null) {
                        remai_recyclerview.setAdapter(merRecylcerAdaper = new MerRecylcerAdaper(domain.getData(), mActivity));
                    } else {
                        merRecylcerAdaper.initRefresh(domain.getData());
                    }
                }
            }
        }
        final Map<String, String> map = new HashMap<>();
        map.put("page","1");
        map.put("pageSize", "5");
        Xutils.GET(HttpUrl.getMerchantsHot, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                final StoreDomain domain = gson.fromJson(result, StoreDomain.class);
                  if(domain.getFlag()){
                      if (domain.getData() != null && domain.getData().size() != 0) {
                          Tools.setCache(mActivity, HttpUrl.getMerchantsHot + "indexpagesize:6", result);
                          if (merRecylcerAdaper == null) {
                              remai_recyclerview.setAdapter(merRecylcerAdaper = new MerRecylcerAdaper(domain.getData(), mActivity));
                          } else {
                              merRecylcerAdaper.initRefresh(domain.getData());
                          }
                      }
                }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    //大减价
    public void merchandisebydajianjia(final String userCity) {
        String cache_result = Tools.getCache(mActivity,HttpUrl.getGiveMethod + "dajianindexpagesize:6"+userCity);
        Gson gson = new Gson();
        if (cache_result != null && !cache_result.equals("")) {
            final StoreDomain domain = gson.fromJson(cache_result, StoreDomain.class);
            if(domain.getFlag()){
                if (domain.getData() != null && domain.getData().size() != 0) {
                    index_dajianjiaall.removeAllViews();
                    for (int i = 0; i < domain.getData().size(); i++) {
                        final StoreDomain.Data dataBean = domain.getData().get(i);
                        View view = View.inflate(mActivity, R.layout.layout_index_sendpoitem, null);
                        ImageView indeximg = view.findViewById(R.id.img);
                        TextView realmoney = view.findViewById(R.id.realmoney);
                        TextView originmoney = view.findViewById(R.id.originmoney);
                        TextView name = view.findViewById(R.id.name);
                        Glide.with(mActivity).load(dataBean.getImg() + "")
                                .crossFade(1000)
                                .centerCrop()
                                .into(indeximg);
                        originmoney.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
                        originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
                        originmoney.getPaint().setAntiAlias(true);// 抗锯齿
                        originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
                        originmoney.setText("¥" + dataBean.getOriginalPrice());
                        realmoney.setText("¥" + dataBean.getPrice());
                        name.setText("" + dataBean.getName());
                        view.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Map<String, Object> map = new HashMap<>();
                                map.put("merchandiseId", dataBean.getId());
                                Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                            }
                        });
                        index_dajianjiaall.addView(view);
                    }

                }
            }
        }
        final Map<String, String> map = new HashMap<>();
        map.put("city", userCity);
        map.put("page","1");
        map.put("pageSize", "6");
        map.put("giveMethod",""+1);
        Xutils.GET(HttpUrl.getGiveMethod, map, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                final StoreDomain domain = gson.fromJson(result, StoreDomain.class);
                if(domain.getFlag()){
                    if (domain.getData() != null && domain.getData().size() != 0) {
                        Tools.setCache(mActivity, HttpUrl.getGiveMethod + "dajianindexpagesize:6", result);
                        index_dajianjiaall.removeAllViews();
                        for (int i = 0; i < domain.getData().size(); i++) {
                            final StoreDomain.Data dataBean = domain.getData().get(i);
                            View view = View.inflate(mActivity, R.layout.layout_index_sendpoitem, null);
                            ImageView indeximg = view.findViewById(R.id.img);
                            TextView realmoney = view.findViewById(R.id.realmoney);
                            TextView originmoney = view.findViewById(R.id.originmoney);
                            TextView name = view.findViewById(R.id.name);
                            Glide.with(mActivity).load(dataBean.getImg() + "")
                                    .crossFade(1000)
                                    .centerCrop()
                                    .into(indeximg);
                            originmoney.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
                            originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中间横线
                            originmoney.getPaint().setAntiAlias(true);// 抗锯齿
                            originmoney.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰
                            originmoney.setText("¥" + dataBean.getOriginalPrice());
                            realmoney.setText("¥" + dataBean.getPrice());
                            name.setText("" + dataBean.getName());
                            view.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    Map<String, Object> map = new HashMap<>();
                                    map.put("merchandiseId", dataBean.getId());
                                    Tools.redirectActivity(mActivity, GeneicStoreInfoActivity.class, map);
                                }
                            });
                            index_dajianjiaall.addView(view);
                        }

                    }
                }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }






}
